www.gusucode.com > 基于马尔科夫随机场的图像分割matlab源码。包括ICM迭代条件模式求解最大后验概率算法 > code23/matlab MRF toy examples/getLogProb.m
% getLogProb(nodes); % get log probability for a node configuration. % res is the results image for which we will evaluate the log prob. % oct. 11, 2003 wtf function [logprob] = getLogProb(nodes, N, M, res); logprob = 0; for iNode = 1:length(nodes) [ln, ii, jj] = getRasterNeighbors(iNode, N, M); node = nodes{iNode}; logprob = log(node.localEvidence(1+res(ii,jj))) + logprob; for nl = 1:node.nLinks link = node.links{nl}; % 0.5 because we count each link twice, in this way [ln,iifar,jjfar] = getRasterNeighbors(link.farsIndex,N,M); logprob = logprob + 0.5* log( link.propMat(res(iifar, jjfar)+1,... res(ii, jj)+1)); end end